package com.ytktt.study.week12.task6;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * TODO
 *
 * @author ytk
 */
public final class KmqBroker<T> { // Broker+Connection

    public static final int CAPACITY = 10000;

    private final Map<String, Kmq<T>> kmqMap = new ConcurrentHashMap<>(64);

    public void createTopic(String name){
        this.kmqMap.putIfAbsent(name, new Kmq<>(name, CAPACITY));
    }

    public Kmq<T> findKmq(String topic) {
        return this.kmqMap.get(topic);
    }

    public KmqProducer<T> createProducer() {
        return new KmqProducer<>(this);
    }

    public KmqConsumer<T> createConsumer() {
        return new KmqConsumer<>(this, "default");
    }

    public KmqConsumer<T> createConsumer(String name) {
        return new KmqConsumer<>(this, name);
    }

}
